package com.dhemery.mack.adapters;

import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;

import com.dhemery.mack.gui.NodeEditor;
import com.dhemery.mack.model.Node;

public class EditorLauncher {
	private final IWorkbenchPage page;
	private final IAdapterFactory factory;

	public EditorLauncher(IWorkbenchPage page, IAdapterFactory factory) {
		this.page = page;
		this.factory = factory;
	}

	public void edit(Node node) {
		IEditorInput editorInput = (IEditorInput)factory.getAdapter(node, IEditorInput.class);
		try {
			page.openEditor(editorInput, NodeEditor.ID);
		} catch (PartInitException e) {
			e.printStackTrace();
		}
	}
}
